package com.ygqh.customs.handler;

import com.ygqh.customs.config.CustomsConfig;
import com.ygqh.customs.domain.PayExInfo;
import com.ygqh.customs.domain.PayExchangeInfoHead;
import com.ygqh.customs.domain.PayExchangeInfoList;
import com.ygqh.customs.model.OrderData;
import com.ygqh.customs.po.YgOrderPayLog;
import com.ygqh.customs.request.PlatDataOpenRequest;
import com.ygqh.customs.service.YgOrderPayLogService;
import com.ygqh.customs.service.YgOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 〈〉
 *
 * @author guohao
 * @date 2019/3/18 17:03
 * @since 1.0.0
 */
@Slf4j
@Component
public class DataUpParamHandler {


    @Autowired
    private YgOrderPayLogService ygOrderPayLogService;
    @Autowired
    private YgOrderService ygOrderService;
    @Autowired
    private CustomsConfig customsConfig;

    public PayExInfo build(PlatDataOpenRequest openRequest) {
        List<YgOrderPayLog> payLogList = ygOrderPayLogService.findByPaymentCode(openRequest.getOrderNo());

        OrderData orderData = ygOrderService.findOrderDataByPaymentCode(openRequest.getOrderNo());

        PayExchangeInfoHead infoHead = new PayExchangeInfoHeadHandler(orderData, payLogList, customsConfig).buildPayExchangeInfoHead();
        List<PayExchangeInfoList> infoLists = new PayExchangeInfoListHandler(orderData, customsConfig).buildPayExchangeInfoLists();
        PayExInfo dataUpSignParam = new PayExInfo();
        dataUpSignParam.setSessionID(openRequest.getSessionID());
        dataUpSignParam.setPayExchangeInfoHead(infoHead);
        dataUpSignParam.setPayExchangeInfoLists(infoLists);
        dataUpSignParam.setCertNo(customsConfig.getCertNo());

        return dataUpSignParam;
    }


}
